package com.linsir.gen.controller;

import com.linsir.core.controller.BaseCrudRestController;
import com.linsir.core.vo.R;
import com.linsir.core.vo.Result;
import com.linsir.core.vo.jsonResults.ResResult;
import com.linsir.gen.dto.SysGenTableDTO;
import com.linsir.gen.entity.SysGenTable;
import com.linsir.gen.service.SysGenTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：linsir
 * @date ：Created in 2022/10/7 23:24
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/v1/sysGenTable/")
public class SysGenTableController extends BaseCrudRestController<SysGenTable> {

    @Autowired
    private SysGenTableService sysGenTableService;

    /*** 
    * @Description: 列表
    * @Param: [sysGenTableDTO] 
    * @return: com.linsir.core.vo.jsonResults.ResResult 
    * @Author: linsir
    * @Date: 2022/10/8 2:33
    */
    @GetMapping("list")
    public ResResult list(SysGenTableDTO sysGenTableDTO)
    {
        return  null;
    }

    /***
    * @Description: 增加
    * @Param: [sysGenTable]
    * @return: com.linsir.core.vo.jsonResults.ResResult
    * @Author: linsir
    * @Date: 2022/10/8 2:42
    */
    @PostMapping("add")
    public ResResult add(SysGenTable sysGenTable) throws Exception {
        R result = null;
        result = exec("增加数据表",()->{
            if (sysGenTableService.createEntity(sysGenTable))
            {
                return Result.SUCCESS();
            }else
            {
                return  Result.FAIL_EXCEPTION("增加失败");
            }
        });
        return  new ResResult(result);
    }

    /***
    * @Description: 删除
    * @Param: [sysGenTableId]
    * @return: com.linsir.core.vo.jsonResults.ResResult
    * @Author: linsir
    * @Date: 2022/10/8 2:43
    */
    public ResResult del(Long sysGenTableId)
    {
        return  null;
    }

    /***
    * @Description: 同步数据库
    * @Param: [sysGenTableId]
    * @return: com.linsir.core.vo.jsonResults.ResResult
    * @Author: linsir
    * @Date: 2022/10/11 0:02
    */
    @GetMapping("synchDb")
    public ResResult synchDb(Long sysGenTableId) throws Exception {
        R result = null;
        result = exec("同步数据库",()->{
            sysGenTableService.synchDb(sysGenTableId);
            return  Result.SUCCESS();
        });
        return new ResResult(result);
    }
}
